#
# Copyright (C) 2007 Rico Schiekel (fire at downgra dot de)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#
# vim:syntax=python:sw=4:ts=4:expandtab

import sys
from utils import patterns
from utils.event_handler import *

EVENTS = patterns(
    (r'^Start wmiirc$', FWrap(sys.exit, 0)),
    (r'^CreateTag', TagCreate()),
    (r'^DestroyTag', TagDestroy()),
    (r'^FocusTag', TagFocus()),
    (r'^FocusTag', TagHistory(15)),
    (r'^UnfocusTag', TagUnfocus()),
    (r'^CreateClient', SecondColumnHack()),
    (r'^LeftBarClick', View()),
    (r'^LeftBarClick', WheelView()),
    (r'^ClientMouseDown', Call(WMII9Menu(['nop', 'close']), dict(close = Kill()))),
    (r'^UrgentTag', TagUrgent()),
    (r'^NotUrgentTag', TagNotUrgent()),
)

# work views (view, add tag, set tag)
for i in range(0, 10):
    EVENTS += patterns(
        (r'^Key Mod1-%d$' % i, View(str(i))),
        (r'^Key Mod1-Shift-%d$' % i, AddTag(str(i))),
        (r'^Key Mod1-Control-%d$' % i, SetTag(str(i))),
    )

# named views (view, add tag, set tag)
NAMED_VIEWS = ['eclipse', 'browser', 'vbox', 'logs', 'monitor']
for i in range(0, len(NAMED_VIEWS)):
    EVENTS += patterns(
        (r'^Key Mod1-F%d$' % (i+1), View(NAMED_VIEWS[i])),
        (r'^Key Mod1-Shift-F%d$' % (i+1), AddTag(NAMED_VIEWS[i])),
        (r'^Key Mod1-Control-F%d$' % (i+1), SetTag(NAMED_VIEWS[i])),
    )

EVENTS += patterns(
    # focus up/down/left/right/h/j/k/l client
    SelectSet(r'^Key Mod1-Shift-', '$', SelectSet.VIM),
    SelectSet(r'^Key Mod1-Shift-', '$', SelectSet.CURSOR),
    (r'^Key Mod1-Tab$', Select('down')),

    # move selected client up/down/left/right/h/j/k/l
    SendSet(r'^Key Mod1-Control-', '$', SendSet.VIM),
    SendSet(r'^Key Mod1-Control-', '$', SendSet.CURSOR),

    # switch to next or previous view
    (r'^Key Mod1-Right$', NextView()),
    (r'^Key Mod1-l$', NextView()),
    (r'^Key Mod1-Left$', PrevView()),
    (r'^Key Mod1-h$', PrevView()),

    # history
    (r'^Key Mod1-plus$', HistoryNext()),
    (r'^Key Mod1-minus$', HistoryPrev()),

    # toggle between managed and floating layer
    (r'^Key Mod1-f$', Toggle()),
    (r'^Key Mod1-Control-f$', SendToggle()),

    # add/set tag for current client selected using dmenu
    (r'^Key Mod1-Shift-t$', AddTag(DMenu(TagGenerator()))),
    (r'^Key Mod1-Control-t$', SetTag(DMenu(TagGenerator()))),

    # remove current client from view
    (r'^Key Mod1-Shift-u$', RemoveTag(active_view)),
    (r'^Key Mod1-Control-u$', SetTag(active_view)),

    # switch column modes
    (r'^Key Mod1-s$', ColMode('stack')),
    (r'^Key Mod1-d$', ColMode()),
    (r'^Key Mod1-m$', ColMode('max')),
    # kill client
    (r'^Key Mod1-Control-c$', Kill()),

    # run applications
    (r'^Key Mod1-Return$', Execute('xterm')),
    (r'^Key Mod1-Shift-Return$', Execute('xterm -fg red -e sudo su -')),
    (r'^Key Mod1-Shift-b$', Execute('set_random_wallpaper.zsh')),
    (r'^Key Mod1-F12$', Execute('xlock')),

    # run application selected using dmenu
    (r'^Key Mod1-p$', Execute(DMenu(ApplicationGenerator()))),
)

APPLICATIONS = dict(quit = Quit(),
                    lock = Execute('xlock'),
                    eclipse = Execute('eclipse'),
                    amarok = Execute('amarok'),
                    firefox = Execute('firefox'),
                    galeon = Execute('galeon'),
                    opera = Execute('opera'),
                    rox = Execute('rox'),
                    virtualbox = Execute('VirtualBox'),
                    wallpaper = Execute('/home/craxyz/bin/random_wallpaper.py'))
EVENTS += patterns(
    (r'^Key Mod1-a$', CallDMenu(APPLICATIONS)),
)
